package com.basic.tcp2;

import com.basic.entity.User;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {

        //监听用户请求
        Socket socket = new Socket(InetAddress.getLocalHost(),8800);

        //发生数据
        //DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
        User user = new User("jjj","123");
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        oos.writeObject(user);
        //接收服务器的响应
        DataInputStream dis = new DataInputStream(socket.getInputStream());
        String result = dis.readUTF();
        System.out.println(result);
        //关闭
        dis.close();
        oos.close();
        socket.close();
    }
}
